package com.wj.hourupdate.datasource;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;

public class SettingDatasource extends SQLiteDatasource {
	
	public SettingDatasource(Context c) {
		super(c);
	}

	public SettingData getSetting(){
		SettingData set = new SettingData();
		Cursor cursor = db.rawQuery("SELECT * FROM " + DatabaseHelper.TB_SETTING, null);
		if(cursor.moveToFirst()){
			set.setIp(cursor.getString(cursor.getColumnIndex(DatabaseHelper.TB_SETTING_COL_IP)));
			set.setPort(cursor.getString(cursor.getColumnIndex(DatabaseHelper.TB_SETTING_COL_PORT)));
		}
		cursor.close();
		return set;
	}
	
	public void saveSetting(String ip, String port){
		String sqlDelete = "DELETE FROM " + DatabaseHelper.TB_SETTING;
		
		db.execSQL(sqlDelete);
		
		ContentValues cv = new ContentValues();
		cv.put(DatabaseHelper.TB_SETTING_COL_IP, ip);
		cv.put(DatabaseHelper.TB_SETTING_COL_PORT, port);
		
		db.insert(DatabaseHelper.TB_SETTING, null, cv);
	}
	
}
